Change in openvpn[master]: Implement epoch key data format
A message that is not in the archive (sent off-list or not yet received): gerrit.1731290343000.I00751c42cb04e30205ba8e6584530831e0d143c5@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to review the following change.
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
14 files changed, 443 insertions(+), 60 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/1
CMakeLists.txt +8 -1
@@ -705,6 +705,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -733,9 +734,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -761,6 +763,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -782,6 +785,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -835,9 +839,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -853,6 +859,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
src/openvpn/crypto.c +102 -35
237 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -518,6 +518,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +76 -1
119 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +189 -16
281 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#2).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 458 insertions(+), 60 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/2
CMakeLists.txt +8 -1
@@ -705,6 +705,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -733,9 +734,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -761,6 +763,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -782,6 +785,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -835,9 +839,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -853,6 +859,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +15 -0
@@ -30,6 +30,21 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +102 -35
237 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -518,6 +518,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +76 -1
119 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +189 -16
281 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#3).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 457 insertions(+), 59 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/3
CMakeLists.txt +8 -1
@@ -705,6 +705,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -733,9 +734,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -761,6 +763,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -782,6 +785,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -835,9 +839,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -853,6 +859,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +15 -0
@@ -30,6 +30,21 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +101 -34
234 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -521,6 +521,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +76 -1
119 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +189 -16
281 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#4).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 456 insertions(+), 59 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/4
CMakeLists.txt +8 -1
@@ -705,6 +705,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -733,9 +734,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -761,6 +763,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -782,6 +785,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -835,9 +839,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -853,6 +859,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +15 -0
@@ -30,6 +30,21 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +100 -34
232 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -522,6 +522,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +76 -1
119 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +189 -16
281 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#5).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 487 insertions(+), 59 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/5
CMakeLists.txt +8 -1
@@ -705,6 +705,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -733,9 +734,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -761,6 +763,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -782,6 +785,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -835,9 +839,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -853,6 +859,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +15 -0
@@ -30,6 +30,21 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +100 -34
232 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -522,6 +522,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +76 -1
119 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#8).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 496 insertions(+), 62 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/8
CMakeLists.txt +8 -1
@@ -703,6 +703,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -731,9 +732,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -759,6 +761,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -780,6 +783,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -833,9 +837,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -851,6 +857,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +14 -0
@@ -30,6 +30,20 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +109 -37
248 lines not on this page · raw message
src/openvpn/crypto.h +1 -0
@@ -527,6 +527,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -38,7 +38,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -314,7 +314,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -367,6 +366,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -496,8 +501,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -430,6 +430,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -499,9 +504,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#10).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 497 insertions(+), 62 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/10
CMakeLists.txt +8 -1
@@ -704,6 +704,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -732,9 +733,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -760,6 +762,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -781,6 +784,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -834,9 +838,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -852,6 +858,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +14 -0
@@ -30,6 +30,20 @@ https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire + Deprecated features ------------------- ``secret`` support has been removed by default.
src/openvpn/crypto.c +109 -37
248 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2761,6 +2761,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3357,6 +3370,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1849,6 +1849,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -431,6 +431,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -500,9 +505,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#11).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_ssl.c
15 files changed, 496 insertions(+), 62 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/11
CMakeLists.txt +8 -1
@@ -704,6 +704,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -732,9 +733,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -760,6 +762,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -781,6 +784,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -834,9 +838,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -852,6 +858,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of= + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +109 -37
248 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1850,6 +1850,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -433,6 +433,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -502,9 +507,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 11
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 12:
(4 comments)
Patchset:
PS12:
light review, spotted a few minor things
File Changes.rst:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/28a72564_50bb6c50 :
PS12, Line 38: Epoch data keys
maybe make that header "epoch data keys & packet format" or so? The text describes keys and format...
http://gerrit.openvpn.net/c/openvpn/+/806/comment/a96b47e7_f7937579 :
PS12, Line 40: ciphers in TLS mode ciphers. This new data format has a number of=
stray =
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/f3bd08f7_4e5efc26 :
PS12, Line 455: goto error_exit;
that goto should not be needed? CRYPT_DROP() expands to CRYPT_ERROR_EXIT() which has the goto
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 10 Jan 2025 08:08:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 12:
(3 comments)
File Changes.rst:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/7cb2c8ce_a1734688 :
PS12, Line 38: Epoch data keys
Quoted 1 line
maybe make that header "epoch data keys & packet format" or so? The text describes keys and format. […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/806/comment/c262c810_6074d03e :
PS12, Line 40: ciphers in TLS mode ciphers. This new data format has a number of=
Quoted 1 line
stray
=
Acknowledged
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/54b550d3_c3929922 :
PS12, Line 455: goto error_exit;
Quoted 1 line
that
gotoshould not be needed?CRYPT_DROP()expands toCRYPT_ERROR_EXIT()which has the goto
Acknowledged
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 10 Jan 2025 09:49:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#13).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 500 insertions(+), 68 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/13
CMakeLists.txt +8 -1
@@ -704,6 +704,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -732,9 +733,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -760,6 +762,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -781,6 +784,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -834,9 +838,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -852,6 +858,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +107 -37
246 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1850,6 +1850,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -433,6 +433,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -502,9 +507,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#14).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 502 insertions(+), 67 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/14
CMakeLists.txt +8 -1
@@ -704,6 +704,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -732,9 +733,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -760,6 +762,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -781,6 +784,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -834,9 +838,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -852,6 +858,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +109 -36
249 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1850,6 +1850,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -433,6 +433,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -502,9 +507,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 14
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#15).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 501 insertions(+), 69 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/15
CMakeLists.txt +8 -1
@@ -704,6 +704,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -732,9 +733,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -760,6 +762,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -781,6 +784,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -834,9 +838,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -852,6 +858,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +6 -0
@@ -1850,6 +1850,12 @@ }#endif +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH )) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) { o->imported_protocol_flags |=CO_USE_CC_EXIT_NOTIFY ;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +10 -2
@@ -433,6 +433,11 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH )) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -502,9 +507,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 15
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 16: Code-Review-2
(1 comment)
Patchset:
PS16:
This ASSERT()s when an epoch-enabled client connects to an epoch-enabled server, but presents non-AEAD ciphers
``` peer info: IV_CIPHERS=none peer info: IV_PROTO=3998 ... AEAD cipher (currently [null-cipher]) required for epoch data format. Exiting due to fatal error ```
(BF-CBC works just as well)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 16
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 03 Feb 2025 15:40:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
Hello cron2, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#17).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 514 insertions(+), 73 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/17
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -0
@@ -1879,6 +1879,13 @@ tls_multi->remote_ciphername, &o->gc); +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +if (push_cipher) { o->ciphername = push_cipher;
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,9 +485,6 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message.
@@ -501,10 +511,16 @@ common_cipher =BSTR (&out); } +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 17
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 17: Code-Review-2
(1 comment)
Patchset:
PS16:
Getting there, so it survives "no AEAD ciphers" now :-)
The next nastiness is "client requests a cipher that the server does not support" - this test is labeled "expect failure", but with v17 it hits an assertion...
``` peer info: IV_CIPHERS=IDEA-CBC peer info: IV_PROTO=3998 (auth succeeds, client-connect runs, ...) Assertion failed at crypto_openssl.c:612 (ciphername) Exiting due to fatal error ```
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 17
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 04 Feb 2025 08:32:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
Hello cron2, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#18).
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 514 insertions(+), 74 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/18
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -1
@@ -1878,9 +1878,15 @@char *push_cipher =ncp_get_best_cipher (o->ncp_ciphers, peer_info, tls_multi->remote_ciphername, &o->gc); -if (push_cipher) { +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } + o->ciphername = push_cipher;return true; }
src/openvpn/ssl.c +77 -1
120 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,15 +485,15 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message. * We postpone switching the cipher to do_up */ const char *common_cipher =get_p2p_ncp_cipher (session, multi->peer_info, &gc); +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +if (!common_cipher) {struct buffer out =alloc_buf_gc (128 , &gc);
@@ -502,9 +515,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 18
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 18: Code-Review-2
(2 comments)
Patchset:
PS18:
Client- and Server-side tests pass now, including NCP malicousness ("none", "ARIA-CBC").
I do not feel comfortable giving a +2 for the crypto bits, but the rest of the changes look good to me.
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/6feaf7c3_3bc9619b :
PS18, Line 3040: if (ks->crypto_options.flags & CO_EPOCH_DATA_KEY_FORMAT)
if we need to do another round of this patch, it would be nice to be consistent with all the other checks and have a comment above the if()
``` /* epoch approaching the 16 bit limit */ ```
or so.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 18
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 04 Feb 2025 10:56:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 18: Code-Review+1
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 18
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 04 Feb 2025 10:57:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 18:
(3 comments)
Patchset:
PS18:
Some minor comments.
Also, I'll read the tests again later. I don't think I fully got them yet.
File tests/unit_tests/openvpn/test_crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/42fb5434_e8016878 :
PS18, Line 877: * the end of array. Iterating through all 65k keys takes a 2-3s, so we
Why is this number changed?
File tests/unit_tests/openvpn/test_ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/47bafe95_4b39c681 :
PS18, Line 642: const uint8_t exp_tag_short[16] =
What makes this short? It's exactly as long as the other.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 18
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 05 Feb 2025 17:01:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: MaxF, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 18:
(2 comments)
File tests/unit_tests/openvpn/test_crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/2fea2111_397e3eef :
PS18, Line 877: * the end of array. Iterating through all 65k keys takes a 2-3s, so we
Quoted 1 line
Why is this number changed?
Because I am stupid and thought that for some reason that maximum epoch of 16bit is 16k when it is actually 65k. The unit tests still works because it just iterated through all the remaining 48k keys but it didn't avoid the 2-3 delay ....
File tests/unit_tests/openvpn/test_ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/854f6f60_4167ef0b :
PS18, Line 642: const uint8_t exp_tag_short[16] =
Quoted 1 line
What makes this short? It's exactly as long as the other.
tag for the short packet id. The name could have been chosen a bit better. It is still a leftover when there was a short and long packet id instead of a short packet id vs epoch packet id.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 18
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Wed, 05 Feb 2025 17:07:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, cron2, flichtenheld.
Hello cron2, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
to look at the new patch set (#19).
The following approvals got outdated and were removed:
Code-Review+1 by cron2
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 515 insertions(+), 74 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/19
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -1
@@ -1878,9 +1878,15 @@char *push_cipher =ncp_get_best_cipher (o->ncp_ciphers, peer_info, tls_multi->remote_ciphername, &o->gc); -if (push_cipher) { +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } + o->ciphername = push_cipher;return true; }
src/openvpn/ssl.c +78 -1
121 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,15 +485,15 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message. * We postpone switching the cipher to do_up */ const char *common_cipher =get_p2p_ncp_cipher (session, multi->peer_info, &gc); +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +if (!common_cipher) {struct buffer out =alloc_buf_gc (128 , &gc);
@@ -502,9 +515,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 19
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: MaxF, flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 19: Code-Review+1
(1 comment)
File src/openvpn/ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/38db66c9_2bc36ec9 :
PS18, Line 3040: if (ks->crypto_options.flags & CO_EPOCH_DATA_KEY_FORMAT)
Quoted 1 line
if we need to do another round of this patch, it would be nice to be consistent with all the other c […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 19
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sun, 09 Feb 2025 15:27:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Patch Set 19: Code-Review+2
(2 comments)
File tests/unit_tests/openvpn/test_crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/b2f3e131_4cc9910e :
PS18, Line 877: * the end of array. Iterating through all 65k keys takes a 2-3s, so we
Quoted 1 line
Because I am stupid and thought that for some reason that maximum epoch of 16bit is 16k when it is a […]
Done
File tests/unit_tests/openvpn/test_ssl.c:
http://gerrit.openvpn.net/c/openvpn/+/806/comment/501376f6_d5a27e2a :
PS18, Line 642: const uint8_t exp_tag_short[16] =
Quoted 1 line
tag for the short packet id. The name could have been chosen a bit better. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 19
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 12 Feb 2025 16:11:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
PATCH v19 1/1 Implement epoch key data format
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/806
This mail reflects revision 19 of this Change.
Acked-by according to Gerrit (reflected above):
MaxF <[email protected]...>
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -1
@@ -1878,9 +1878,15 @@char *push_cipher =ncp_get_best_cipher (o->ncp_ciphers, peer_info, tls_multi->remote_ciphername, &o->gc); -if (push_cipher) { +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } + o->ciphername = push_cipher;return true; }
src/openvpn/ssl.c +78 -1
121 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,15 +485,15 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message. * We postpone switching the cipher to do_up */ const char *common_cipher =get_p2p_ncp_cipher (session, multi->peer_info, &gc); +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +if (!common_cipher) {struct buffer out =alloc_buf_gc (128 , &gc);
@@ -502,9 +515,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
[Openvpn-devel] [PATCH applied] Re: Implement epoch key data format
Finally!
I think I've tested all there is in my repertoire (run this code against itself and against earlier "non epoch" OpenVPN versions, both as client and as server) - and managed to find a few nice explosions in v17+18 :-)
MaxF has done the crypto review, both on "is the OpenVPN protocol documentation in the RFC-to-be cryptographically sound" and "does the code confirm to the documentation" and +2'ed the last patch now... in it goes!
Your patch has been applied to the master branch.
commit 9f4670fc718a8c16280d60c3e2d4ad29cffa04c4
Author: Arne Schwabe Date: Wed Feb 12 17:13:11 2025 +0100
Implement epoch key data format
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: MaxF <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30845.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#20) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
The following approvals got outdated and were removed:
Code-Review+1 by cron2, Code-Review+2 by MaxF
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30845.html
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 515 insertions(+), 74 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/06/806/20
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -1
@@ -1878,9 +1878,15 @@char *push_cipher =ncp_get_best_cipher (o->ncp_ciphers, peer_info, tls_multi->remote_ciphername, &o->gc); -if (push_cipher) { +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } + o->ciphername = push_cipher;return true; }
src/openvpn/ssl.c +78 -1
121 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,15 +485,15 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message. * We postpone switching the cipher to do_up */ const char *common_cipher =get_p2p_ncp_cipher (session, multi->peer_info, &gc); +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +if (!common_cipher) {struct buffer out =alloc_buf_gc (128 , &gc);
@@ -502,9 +515,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 20
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/806?usp=email )
Change subject: Implement epoch key data format
......................................................................
Implement epoch key data format
With DCO and possible future hardware assisted OpenVPN acceleration we are approaching the point where 32 bit IVs are not cutting it any more, especially if we are limiting the IVs to the safe limits of AES-GCM where the limit is more 2^29.
To illustrate the problem, some back of the envelope math here:
If we want to keep the current 3600s renegotiation interval and have a safety margin of 25% (when we trigger renegotiation) we have about 3.2 million packets (2*32 * 0.7) to work with. That translates to about 835k packets per second. Currently, implementation trigger the renegotiation at 0xff00000000 or at 7/8 of the AEAD usage limit.
With 1300 Byte packets that translates into 8-9 Gbit/s. That is far from unrealistic any more. Current DCO implementations are already in spitting distance to that or might even reach (for a single client connection) that if you have extremely fast
single core performance CPU.
With the AEAD usage limit, these limits are almost a factor of 8 lower so with the limit becomes 1-2 GBit/s. This is already reached without DCO on some platforms.
This introduces the epoch data format for AEAD data channel ciphers in TLS mode ciphers. No effort has been made to support larger packet counters in any other scenario since those are all legacy. This uses the same approach of epoch keys as (D)TLS 1.3 does and switches the data channel regularly for affected AEAD ciphers when reaching the usage limit.
For Chacha20-Poly1305, which does not suffer the same problems as AES-GCM, the full 48 bit of packet counter are used only after that the same logic to switch to a new key as with AES-GCM is done.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30845.html
---
M CMakeLists.txt
M Changes.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
M src/openvpn/dco.h
M src/openvpn/init.c
M src/openvpn/multi.c
M src/openvpn/ssl.c
M src/openvpn/ssl_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/tls_crypt.c
M tests/Makefile.am
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c
16 files changed, 515 insertions(+), 74 deletions(-)
CMakeLists.txt +8 -1
@@ -706,6 +706,7 @@ target_sources(test_auth_token PRIVATE src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -734,9 +735,10 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c - src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c + src/openvpn/crypto.c src/openvpn/cryptoapi.c src/openvpn/env_set.c src/openvpn/mss.c
@@ -762,6 +764,7 @@ ) target_sources(test_ncp PRIVATE + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -783,6 +786,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
@@ -836,9 +840,11 @@ target_compile_options(test_networking PRIVATE -UNDEBUG) target_sources(test_networking PRIVATE src/openvpn/networking_sitnl.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c + src/openvpn/crypto_epoch.c src/openvpn/otime.c src/openvpn/packet_id.c )
@@ -854,6 +860,7 @@ tests/unit_tests/openvpn/mock_win32_execve.c src/openvpn/argv.c src/openvpn/base64.c + src/openvpn/crypto_epoch.c src/openvpn/crypto_mbedtls.c src/openvpn/crypto_openssl.c src/openvpn/crypto.c
Changes.rst +13 -0
@@ -35,6 +35,19 @@ replaced by the default ciphers used by OpenVPN, making it easier to add an allowed cipher without having to spell out the default ciphers. +Epoch data keys and packet format + This introduces the epoch data format for AEAD data channel + ciphers in TLS mode ciphers. This new data format has a number of + improvements over the standard "DATA_V2" format. + + - AEAD tag at the end of packet which is more hardware implementation + friendly + - Automatic key switchover when cipher usage limits are hit, similar to + the epoch data keys in (D)TLS 1.3 + - 64 bit instead of 32 bit packet ids to allow the data channel to be + ready for 10 GBit/s without having frequent renegotiation + - IV constructed with XOR instead of concatenation to not have (parts) of + the real IV on the wire Deprecated features -------------------
src/openvpn/crypto.c +108 -38
250 lines not on this page · raw message
src/openvpn/crypto.h +2 -0
@@ -525,6 +525,7 @@* * @param opt Crypto options for this packet, contains replay state. * @param pin Packet ID read from packet. +* @param epoch Epoch read from packet or 0 when epoch is not used. * @param error_prefix Prefix to use when printing error messages. * @param gc Garbage collector to use. *
@@ -532,6 +533,7 @@*/ bool crypto_check_replay (struct crypto_options *opt,const struct packet_id_net *pin, +uint16_t epoch,const char *error_prefix,struct gc_arena *gc);
src/openvpn/crypto_backend.h +1 -1
@@ -39,7 +39,7 @@#include "basic.h" #include "buffer.h" -/* TLS uses a tag of 128 bytes, let's do the same for OpenVPN */ +/* TLS uses a tag of 128 bits, let's do the same for OpenVPN */ #define OPENVPN_AEAD_TAG_LENGTH 16/* Maximum cipher block size (bytes) */
src/openvpn/dco.h +14 -0
@@ -249,6 +249,15 @@*/ const char *dco_get_supported_ciphers (void ); +/** +* Return whether the dco implementation supports the new protocol features of +* a 64 bit packet counter and AEAD tag at the end. +*/ +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t ;
@@ -380,5 +389,10 @@return "" ; } +static inline bool +dco_supports_epoch_data (struct context *c) +{ +return false; +}#endif /* defined(ENABLE_DCO) */ #endif /* ifndef DCO_H */
src/openvpn/init.c +22 -0
@@ -2788,6 +2788,19 @@ } } +/* Ensure that for epoch data format is only enabled if also data v2 +* is enabled */ +bool epoch_data = (c->options.imported_protocol_flags &CO_EPOCH_DATA_KEY_FORMAT ); +bool datav2_enabled = (c->options.peer_id >=0 && c->options.peer_id <MAX_PEER_ID ); + +if (epoch_data && !datav2_enabled) + { +msg (D_PUSH_ERRORS ,"OPTIONS ERROR: Epoch key data format tag requires " +"data v2 (peer-id) to be enabled." ); +return false; + } + +if (found &OPT_P_PUSH_MTU ) {/* MTU has changed, check that the pushed MTU is small enough to
@@ -3384,6 +3397,15 @@ to.push_peer_info_detail =1 ; } +/* Check if the DCO drivers support the epoch data format */ +if (dco_enabled (options)) + { + to.data_epoch_supported =dco_supports_epoch_data (c); + } +else + { + to.data_epoch_supported = true; + }/* should we not xmit any packets until we get an initial * response from client? */
src/openvpn/multi.c +7 -1
@@ -1878,9 +1878,15 @@char *push_cipher =ncp_get_best_cipher (o->ncp_ciphers, peer_info, tls_multi->remote_ciphername, &o->gc); -if (push_cipher) { +/* Enable epoch data key format if supported and AEAD cipher in use */ +if (tls_multi->session[TM_ACTIVE ].opt->data_epoch_supported + && (proto &IV_PROTO_DATA_EPOCH ) &&cipher_kt_mode_aead (push_cipher)) + { + o->imported_protocol_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } + o->ciphername = push_cipher;return true; }
src/openvpn/ssl.c +78 -1
121 lines not on this page · raw message
src/openvpn/ssl_common.h +6 -3
@@ -315,7 +315,6 @@/* from command line */ bool single_session; -bool disable_occ;int mode;bool pull;/**
@@ -368,6 +367,12 @@const char *config_ciphername;const char *config_ncp_ciphers; +/** whether our underlying data channel supports new data channel +* features (epoch keys with AEAD tag at the end). This is always true +* for the internal implementation but can be false for DCO +* implementations */ +bool data_epoch_supported; +bool tls_crypt_v2;const char *tls_crypt_v2_verify_script;
@@ -497,8 +502,6 @@*/ int key_id; -int limit_next;/* used for traffic shaping on the control channel */ -int verify_maxlevel;char *common_name;
src/openvpn/ssl_ncp.c +22 -6
@@ -411,7 +411,8 @@ }static void -p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session) +p2p_ncp_set_options (struct tls_multi *multi,struct tls_session *session, +const char *common_cipher) {/* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =extract_iv_proto (multi->peer_info);
@@ -433,6 +434,18 @@ session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; } +if (session->opt->data_epoch_supported && (iv_proto_peer &IV_PROTO_DATA_EPOCH ) + && common_cipher &&cipher_kt_mode_aead (common_cipher)) + { + session->opt->crypto_flags |=CO_EPOCH_DATA_KEY_FORMAT ; + } +else + { +/* The peer might have changed its ciphers options during reconnect, +* ensure we clear the flag if we previously had it enabled */ + session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
@@ -472,15 +485,15 @@void p2p_mode_ncp (struct tls_multi *multi,struct tls_session *session) { -/* Set the common options */ -p2p_ncp_set_options (multi, session); -struct gc_arena gc =gc_new ();/* Query the common cipher here to log it as part of our message. * We postpone switching the cipher to do_up */ const char *common_cipher =get_p2p_ncp_cipher (session, multi->peer_info, &gc); +/* Set the common options */ +p2p_ncp_set_options (multi, session, common_cipher); +if (!common_cipher) {struct buffer out =alloc_buf_gc (128 , &gc);
@@ -502,9 +515,12 @@ }msg (D_TLS_DEBUG_LOW ,"P2P mode NCP negotiation result: " -"TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s" , +"TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s" , (bool )(session->opt->crypto_flags &CO_USE_TLS_KEY_MATERIAL_EXPORT ), - multi->use_peer_id, multi->peer_id, common_cipher); + multi->use_peer_id, + multi->peer_id, + (bool )(session->opt->crypto_flags &CO_EPOCH_DATA_KEY_FORMAT ), + common_cipher);gc_free (&gc); }
src/openvpn/tls_crypt.c +1 -1
@@ -301,7 +301,7 @@struct buffer tmp = *src;ASSERT (buf_advance (&tmp,TLS_CRYPT_OFF_PID ));ASSERT (packet_id_read (&pin, &tmp, true)); -if (!crypto_check_replay (opt, &pin, error_prefix, &gc)) +if (!crypto_check_replay (opt, &pin,0 , error_prefix, &gc)) {CRYPT_ERROR ("packet replay" ); }
tests/Makefile.am +1 -0
@@ -52,6 +52,7 @@ unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/Makefile.am +6 -0
@@ -86,6 +86,7 @@ $(top_srcdir)/src/compat/compat-strsep.c \ $(top_srcdir)/src/openvpn/crypto.c \ $(top_srcdir)/src/openvpn/cryptoapi.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -132,6 +133,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -160,6 +162,7 @@ $(top_srcdir)/src/openvpn/base64.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/env_set.c \
@@ -179,6 +182,7 @@ $(top_srcdir)/src/openvpn/networking_sitnl.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -250,6 +254,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
@@ -285,6 +290,7 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_epoch.c \ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ $(top_srcdir)/src/openvpn/crypto_openssl.c \ $(top_srcdir)/src/openvpn/otime.c \
tests/unit_tests/openvpn/test_crypto.c +6 -6
@@ -874,17 +874,17 @@struct crypto_options *co = &data->co;/* Modify the receive epoch and keys to have a very high epoch to test -* the end of array. Iterating through all 16k keys takes a 2-3s, so we +* the end of array. Iterating through all 65k keys takes a 2-3s, so we * avoid this for the unit test */ - co->key_ctx_bi.decrypt.epoch =16000 ; - co->key_ctx_bi.encrypt.epoch =16000 ; + co->key_ctx_bi.decrypt.epoch =65500 ; + co->key_ctx_bi.encrypt.epoch =65500 ; - co->epoch_key_send.epoch =16000 ; - co->epoch_key_recv.epoch =16000 + co->epoch_data_keys_future_count; + co->epoch_key_send.epoch =65500 ; + co->epoch_key_recv.epoch =65500 + co->epoch_data_keys_future_count;for (uint16_t i =0 ; i < co->epoch_data_keys_future_count; i++) { - co->epoch_data_keys_future[i].epoch =16001 + i; + co->epoch_data_keys_future[i].epoch =65501 + i; }/* Move the last few keys until we are close to the limit */
tests/unit_tests/openvpn/test_ssl.c +220 -16
327 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/806?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I00751c42cb04e30205ba8e6584530831e0d143c5
Gerrit-Change-Number: 806
Gerrit-PatchSet: 20
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged